import { Body, Controller } from '@nestjs/common';
import { EverydayDataService } from './everyday-data.service';
import {
  Crud,
  CrudController,
  CrudRequest,
  Override,
  ParsedRequest,
} from '@dataui/crud';
import { EverydayData } from '@/module/everyday-data/entities/everyday-datum.entity';
import { CreateEverydayDatumDto } from '@/module/everyday-data/dto/create-everyday-datum.dto';

@Crud({
  model: {
    type: EverydayData,
  },
  dto: {
    create: CreateEverydayDatumDto,
  },
  query: {
    join: {
      fileUploads: {
        eager: true,
        // required: true,
      },
      testingMachine: {
        eager: true,
        required: true,
      },
      'testingMachine.user': {
        eager: true,
        required: true,
      },
    },
  },
})
@Controller('everyday-data')
export class EverydayDataController implements CrudController<EverydayData> {
  constructor(public service: EverydayDataService) {}

  @Override()
  async createOne(
    @ParsedRequest() req: CrudRequest,
    @Body() dto: CreateEverydayDatumDto,
  ): Promise<any> {
    console.log(req, dto);
    const result = await this.service.createOneByEverydayData(req, dto);
    return result;
  }

  @Override()
  async deleteOne(@ParsedRequest() req: CrudRequest): Promise<any> {
    const result = await this.service.deleteOne(req);
    return result;
  }
}
